package com.idea.zd.sys.train.thread;

public class JoinThreadTest implements Runnable {


    private int i;
    @Override
    public void run() {

        for(; i < 300; i++){
            System.out.println(Thread.currentThread().getName()+" :"+i);
        }
    }

    public static void main(String [] args) throws InterruptedException {
        JoinThreadTest joinThreadTest = new JoinThreadTest();
        Thread thread = new Thread(joinThreadTest,"没有join的线程");
        Thread thread1 = new Thread(joinThreadTest,"join后的线程");

        //thread1.start();
        thread.start();
        for (int i = 0; i < 100; i++){


            System.out.println(Thread.currentThread().getName()+" :"+i);

            if(i == 20){
                thread1.start();

                //main线程必须等待tread1执行完后才会向下执行
                thread1.join();
            }
        }
    }
}
